<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>防火检查-地图</title>
	<!-- WEB -->
	<script type="text/javascript" src="./plugin/web/jquery/jquery.min.js"></script>
	<link href="./plugin/web/bootstrap/css/bootstrap.min.css" rel="stylesheet">
	<script type="text/javascript" src="./plugin/web/bootstrap/js/bootstrap.min.js"></script>
	<!-- data -->
	<style type="text/css">
		#toolbar1 {
			position: absolute;
			top: 20px;
			left: 20px;
			width: 500px;
			text-align: center;
			z-index: 9999;
			border-radius: 4px;
		}

	</style>
    <script type="text/javascript">
		if (window.addEventListener) {
		    //为window注册message事件并绑定监听函数
		    window.addEventListener('message', receiveMsg, false);
		}else {
		    window.attachEvent('message', receiveMsg);
		}
		//监听函数，接收一个参数--Event事件对象
		function receiveMsg(e){
			let obj = e.data;
		    // 地图交互消息监听
		    if(obj.type == "gisMapMessage"){
					if (obj.data.key == "tdtLoad" && obj.data.value){
						//tdtType为true时，天地图加载成功可以执行定位
						console.log("tdtInfo交互---天地图加载完成",obj.data.value.tdtType)
						// panTo([116.25284,40.28284])
					}else if(obj.data.key == "initInfo" && obj.data.value){
					// initType为true时，map初始化成功
		    		console.log("initInfo交互---地图加载完成",obj.data.value.initType);
						panToByGeo();
					}
		    }else if(obj.type == "gisLayerMessage"){
				if(obj.data.key == "localInfo" && obj.data.value){
					// localInfo
					console.log("localInfo交互 --- 当前定位完成",obj.data.value.localInfo);
				} else if(obj.data.key == "polygonInfo" && obj.data.value) {
					// polygonInfo 地块信息监听
					console.log("polygonInfo交互 --- 房屋信息",obj.data.value.polygonInfo);
				} else if(obj.data.key == "searchInfo" && obj.data.value) {
					// serchInfo 地块信息监听
					console.log("searchInfo交互 --- 搜索房屋成功",obj.data.value.searchType);
				}
			}
		}
		// 发送消息
		function sendMessage(type,data){
			// 向子页面传递消息
			let iframe = document.getElementById("gisIframe");
			iframe.contentWindow.postMessage({type: type, data: data},'*');
		}
	</script>
</head>
<body style="margin:0;overflow:hidden;width:100%;height:100%;position:absolute;top:0;background-color:transparent;">
<div id="toolbar1" class="panel panel-primary">
	<div class='panel-heading'>
		<h5 class='panel-title text-center'>功能交互</h5>
	</div>
	<div class='panel-body content'>
		<input type="button" class="btn btn-default" onclick="panTo()" value="更新定位"></input>
		<input type="button" class="btn btn-default" onclick="panToByGeo()" value="搜索定位房屋"></input>
		<input type="button" class="btn btn-default" onclick="addTDT_img()" value="切换影像底图"></input>
		<input type="button" class="btn btn-default" onclick="addTDT_vec()" value="切换矢量底图"></input>
	</div>
</div>
<iframe id="gisIframe" src="./ZJF_fin.html" style="width:100%;height:100%;background-color:transparent;border:rgba(255,255,255,0);"></iframe>
	<script>
		/**
		 * 初始化缩放到 给定经纬度和地图等级
		 */
		function panTo(){
			let message = { "key": "panTo", "value": { "lonlat": [116.42611685, 40.134494794999995] } };
			sendMessage('gisLayerMessage', message);
		}
		function addTDT_img(){
			let message = { "key": "addTDT_img", "value": { "isSelect": true } };
			sendMessage('gisLayerMessage', message);
		}
		function addTDT_vec(){
			let message = { "key": "addTDT_vec", "value": {"isSelect": true } };
			sendMessage('gisLayerMessage', message);
		}
		function panToByGeo() {
			// 110114001020487
			let message = { "key": "panToByGeo", "value": { "geo": geo } };
			sendMessage('gisLayerMessage', message);
		}
		let geo = null;
		// {"type" : "Feature", "geometry" : {"type" : "MultiPolygon", "coordinates" : [[[[116.405619249,39.663738414],[116.405706602,39.663741818],[116.405710445,39.663643196],[116.405623273,39.663639173],[116.405619249,39.663738414]]]]}, "properties" : {"fwbh" : "110115000849643", "address" : "无组黄徐路（街、巷）无号", "hzxm" : "吴振彬"}}
	</script>
</html>
